package com.zx.inf.sys.service;

import com.zaxxer.hikari.HikariDataSource;
import com.zx.inf.sys.dao.InfDsInfoMapper;
import com.zx.inf.sys.entity.InfDsInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DataSourceService {


    @Autowired
    private InfDsInfoMapper infDsInfoMapper;

    private HikariDataSource createDataSource(InfDsInfo dsInfo) {
        HikariDataSource dataSource = new HikariDataSource();
        dataSource.setJdbcUrl(dsInfo.getDsUrl());
        dataSource.setUsername(dsInfo.getDsAccount());
        dataSource.setPassword(dsInfo.getDsPassword());
        if (dsInfo.getDsType() == 1) {
            dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
        } else if (dsInfo.getDsType() == 2) {
            dataSource.setDriverClassName("ru.yandex.clickhouse.ClickHouseDriver");
        }
        return dataSource;
    }

    public int addDataSource(InfDsInfo infDsInfo) {
        return infDsInfoMapper.insert(infDsInfo);
    }
}
